"""登陆"""

import g


def getApiData():
    """
    统一定义参数类型！！不定义会报错
    """
    return [
        {"var": "bindUid", "type": "string", "desc": "binduid", "minlen": 1},
        {"var": "sid", "type": "int", "desc": "区服sid"},
        {"var": "extData", "type": "dict", "desc": "额外数据"}
    ]


async def proc(unique_key, gateway_url, data, *args, **kwargs):
    _res = {
        "s": 1
    }

    _bindUid = data.bindUid.strip()
    _sid = data.sid
    _extData = data.extData
    _ip = data.ip

    _userInfo = await g.mdb.find1("userinfo", {"binduid": _bindUid, "sid": _sid}, fields={"_id": 0}) or {}
    if _userInfo:
        uid = _userInfo["uid"]

    else:
        # 创建用户
        _userInfo = await g.m["user.fun"].creatPlayer(_bindUid, _sid, _ip, _extData, gateway_url=gateway_url)
        uid = _userInfo["uid"]

    _res["uid"] = uid
    _res["d"] = {
        "gud": await g.Model.UserInfo.getGud(uid),
    }

    return _res


if __name__ == '__main__':
    proc(1, 2, 3)
